<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      width: 460px;
      height: 40px;
      margin: 100px auto;
      border: 2px solid blue;
    }

    .box input {
      width: 385px;
      height: 34px;
      outline: none;
      border: 0;
      color: gray;
      font-size: 12px;
    }

    .box button {
      width: 70px;
      height: 40px;
      outline: none;
      background-color: blue;
      color: white;
      font-size: 14px;
    }
  </style>
</head>

<body>
  <div class="box">
    <input type="text" value="手机">
    <button>搜索</button>
  </div>
  <script>
    var text = document.querySelector('input');
    // 注册事件  获取焦点事件 onfocus
    text.onfocus = function () {
      if (this.value === '手机') {
        this.value = '';
      }
      // 获得焦点需要把文本框里面的的文字颜色变深
      this.style.color = '#333'
    }
    // 注册事件  失去焦点事件 onblur
    text.onblur = function () {
      if (this.value === '') {
        this.value = '手机';
      }
      // 获得焦点需要把文本框里面的的文字颜色变浅
      this.style.color = 'gray';
    }
  </script>
</body>

</html>